using Microsoft.AspNetCore.Mvc;
using zhwy.saas.api.Entity.Other;
using zhwy.saas.api.Models;
using zhwy.saas.api.Models.Other.Images;
using zhwy.saas.api.Services.Sinterface;
using zhwy.saas.api.Services.Sinterface.Other;

namespace zhwy.saas.api.Controllers.V1.Other
{
    /// <summary>
    /// 图片服务
    /// </summary>
    [ApiVersion("1.0")]
    public class ImagesController : BaseController<ImagesEntity>
    {
        private readonly IImagesService _imagesService;
        private readonly ICurrentUserService _currentUserService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="imagesService">租户服务</param>
        /// <param name="currentUserService"></param>
        public ImagesController(IImagesService imagesService,
            ICurrentUserService currentUserService)
            : base(imagesService)
        {
            _imagesService = imagesService;
            _currentUserService = currentUserService;
        }

        /// <summary>
        /// 添加图片信息
        /// </summary>
        /// <param name="files">图片信息</param>
        /// <returns>添加结果</returns>
        /// <response code="200">添加成功</response>
        /// <response code="400">添加失败</response>
        [HttpPost("upload")]
        public async Task<ApiResponseModel<ImagesRes>> Add(IFormFile files)
        {
            var userid = _currentUserService.GetUserId();
            var tenantid = _currentUserService.GetTenantId();
            
            // 从请求头获取sysUploadType
            string sysUploadType = "system";
            if (HttpContext.Request.Headers.TryGetValue("sysuploadtype", out var headerValue))
            {
                sysUploadType = headerValue.ToString();
            }

            var res = await _imagesService.AddImages(files, userid, tenantid, sysUploadType);

            return GetResponseModel<ImagesRes>(res);
        }

    }
}
